﻿/******************************************************************************
 * 【本类功能概述】                                 					      *
 *  版权所有（C）2017-20XX，匠梦科技                                         *
 *  保留所有权利。                                                            *
 ******************************************************************************
 *  作者 : <hughjk>
 *  创建时间:2019年5月19日 14:59:28
 *  文件描述:扩展代码
 *****************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using UnityEngine;
using Debug = UnityEngine.Debug;
using Random = UnityEngine.Random;
namespace Util
{
    #region 自定义字符串解析类

    public struct DicIntString
    {
        public Dictionary<int, string> vs;
        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public string this[int index]
        {
            get
            {
                string v = "-1";
                if (!vs.TryGetValue(index, out v))
                {
                    v = "-1";
                }
                return v;
            }
        }

        public DicIntString(string s)
        {
            if (s == string.Empty)
                vs = new Dictionary<int, string>();
            else
                vs = s.toDictIntString();
        }

        public Dictionary<int, string> toDic()
        {
            return vs;
        }
    }

    public struct DicIntInt
    {
        public Dictionary<int, int> vs;
        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public int this[int index]
        {
            get
            {
                int v = -1;
                if (!vs.TryGetValue(index, out v))
                {
                    v = -1;
                }
                return v;
            }
        }

        public DicIntInt(string s)
        {
            if (s == string.Empty)
                vs = new Dictionary<int, int>();
            else
                vs = s.toDictIntInt();
        }

        public Dictionary<int, int> toDic()
        {
            return vs;
        }
    }

    public struct DicIntFloat
    {
        public Dictionary<int, float> vs;
        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public float this[int index]
        {
            get
            {
                float v = -1;
                if (!vs.TryGetValue(index, out v))
                {
                    v = -1;
                }
                return v;
            }
        }

        public DicIntFloat(string s)
        {
            if (s == string.Empty)
                vs = new Dictionary<int, float>();
            else
                vs = s.toDictIntFloat();
        }

        public Dictionary<int, float> toDic()
        {
            return vs;
        }
    }

    //数组字符串 例如: as|sdd|dff
    public struct ArrayString
    {
        private List<string> vs;

        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public string this[int index]
        {
            get
            {
                string v = "-1";
                if (index >= 0 && index < vs.Count && vs != null)
                {
                    v = vs[index];
                }
                return v;
            }
        }

        public ArrayString(string s)
        {
            if (s == string.Empty)
                vs = new List<string>();
            else
                vs = s.toStringList(StringTool.Split1);
        }

        public List<string> toList()
        {
            return vs;
        }
    }

    //矩阵字符串 例如:as|sdd|dff/as|sdd|dff/as|sdd|dff
    public struct MatrixString
    {
        private List<List<string>> vs;
        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public string this[int row, int pos]
        {
            get
            {
                string v = "-1";
                if (row >= 0 && row < vs.Count && vs != null)
                {
                    if (pos >= 0 && pos < vs[row].Count && vs[row] != null)
                        v = vs[row][pos];
                }
                return v;
            }
        }

        public MatrixString(string s)
        {
            if (s == string.Empty)
                vs = new List<List<string>>();
            else
                vs = s.toStringMatrixList(StringTool.Split2, StringTool.Split1);
        }

        public List<List<string>> toList()
        {
            return vs;
        }
    }

    //空间字符串 例如:as|sdd|dff/as|sdd|dff/as|sdd|dff^as|sdd|dff/as|sdd|dff/as|sdd|dff
    public struct SpaceString
    {
        private List<List<List<string>>> vs;
        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public string this[int axis1, int axis2, int axis3]
        {
            get
            {
                string v = "-1";
                if (axis1 >= 0 && axis1 < vs.Count && vs != null)
                    if (axis2 >= 0 && axis2 < vs[axis1].Count && vs[axis1] != null)
                        if (axis3 >= 0 && axis3 < vs[axis1][axis2].Count && vs[axis1][axis2] != null)
                            v = vs[axis1][axis2][axis3];
                return v;
            }
        }

        public SpaceString(string s)
        {
            if (s == string.Empty)
                vs = new List<List<List<string>>>();
            else
                vs = s.toStringSpaceList(StringTool.Split3, StringTool.Split2, StringTool.Split1);
        }

        public List<List<List<string>>> toList()
        {
            return vs;
        }
    }

    //数组Int 例如: 1|2|3|2
    public struct ArrayInt
    {
        private List<int> vs;

        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public int this[int index]
        {
            get
            {
                int v = -1;
                if (index >= 0 && index < vs.Count && vs != null)
                {
                    v = vs[index];
                }
                return v;
            }
        }

        public ArrayInt(string s)
        {
            if (s == string.Empty)
                vs = new List<int>();
            else
                vs = s.toIntList(StringTool.Split1);
        }

        public List<int> toList()
        {
            return vs;
        }
    }

    //矩阵Int 例如: 1|2|3/1|2|3/1|2|3
    public struct MatrixInt
    {
        private List<List<int>> vs;

        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public int this[int row, int pos]
        {
            get
            {
                int v = -1;
                if (row >= 0 && row < vs.Count && vs != null)
                {
                    if (pos >= 0 && pos < vs[row].Count && vs[row] != null)
                        v = vs[row][pos];
                }
                return v;
            }
        }

        public MatrixInt(string s)
        {
            if (s == string.Empty)
                vs = new List<List<int>>();
            else
                vs = s.toIntMatrixList(StringTool.Split2, StringTool.Split1);
        }

        public List<List<int>> toList()
        {
            return vs;
        }
    }

    //空间Int 例如:as|sdd|dff/as|sdd|dff/as|sdd|dff^as|sdd|dff/as|sdd|dff/as|sdd|dff
    public struct SpaceInt
    {
        private List<List<List<int>>> vs;
        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public int this[int axis1, int axis2, int axis3]
        {
            get
            {
                int v = -1;
                if (axis1 >= 0 && axis1 < vs.Count && vs != null)
                    if (axis2 >= 0 && axis2 < vs[axis1].Count && vs[axis1] != null)
                        if (axis3 >= 0 && axis3 < vs[axis1][axis2].Count && vs[axis1][axis2] != null)
                            v = vs[axis1][axis2][axis3];
                return v;
            }
        }

        public SpaceInt(string s)
        {
            if (s == string.Empty)
                vs = new List<List<List<int>>>();
            else
                vs = s.toIntSpaceList(StringTool.Split3, StringTool.Split2, StringTool.Split1);
        }

        public List<List<List<int>>> toList()
        {
            return vs;
        }
    }

    //数组Float 例如:1|2.3|3.2|2
    public struct ArrayFloat
    {
        private List<float> vs;

        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public float this[int index]
        {
            get
            {
                float v = -1;
                if (index >= 0 && index < vs.Count && vs != null)
                {
                    v = vs[index];
                }
                return v;
            }
        }

        public ArrayFloat(string s)
        {
            if (s == string.Empty)
                vs = new List<float>();
            else
                vs = s.toFloatList(StringTool.Split1);
        }

        public List<float> toList()
        {
            return vs;
        }
    }

    //矩阵Float 1|2.3|3.2|2/1|2.3|3.2|2/1|2.3|3.2|2
    public struct MatrixFloat
    {
        private List<List<float>> vs;

        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public float this[int row, int pos]
        {
            get
            {
                float v = -1;
                if (row >= 0 && row < vs.Count && vs != null)
                {
                    if (pos >= 0 && pos < vs[row].Count && vs[row] != null)
                        v = vs[row][pos];
                }
                return v;
            }
        }

        public MatrixFloat(string s)
        {
            if (s == string.Empty)
                vs = new List<List<float>>();
            else
                vs = s.toFloatMatrixList(StringTool.Split2, StringTool.Split1);
        }

        public List<List<float>> toList()
        {
            return vs;
        }
    }

    //空间Float 1|2.3|3.2|2/1|2.3|3.2|2/1|2.3|3.2|2
    public struct SpaceFloat
    {
        private List<List<List<float>>> vs;
        public int Count { get { if (vs == null) { return 0; } return vs.Count; } }

        public float this[int axis1, int axis2, int axis3]
        {
            get
            {
                float v = -1;
                if (axis1 >= 0 && axis1 < vs.Count && vs != null)
                    if (axis2 >= 0 && axis2 < vs[axis1].Count && vs[axis1] != null)
                        if (axis3 >= 0 && axis3 < vs[axis1][axis2].Count && vs[axis1][axis2] != null)
                            v = vs[axis1][axis2][axis3];
                return v;
            }
        }

        public SpaceFloat(string s)
        {
            if (s == string.Empty)
                vs = new List<List<List<float>>>();
            else
                vs = s.toFloatSpaceList(StringTool.Split3, StringTool.Split2, StringTool.Split1);
        }

        public List<List<List<float>>> toList()
        {
            return vs;
        }
    }

    #endregion 自定义字符串解析类
}
